package com.longjianghuasheng.logistics.business.home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.ext.commit
import com.longjianghuasheng.logistics.network.apiService
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine

class HomeViewModel : BaseMultiStateViewModel() {

    private val result by lazy {
        MutableLiveData<NewsResponse>()
    }

    var city = ""

    val convertResult = result.map {

        mutableListOf(
            HomeBean(TYPE_TITLE, it),
            HomeBean(TYPE_BANNER, it),
            HomeBean(TYPE_NEWS, it)
        )
    }

    fun getHome() {

        getData2(
            { if (page == 1) HttpRequestCoroutine.getHome() else apiService.news_list(page) },
            result
        )

    }


}